package com.aizhixin.lab.course.classes.repository;

import com.aizhixin.lab.course.classes.entity.CourseClassStu;

import java.util.ArrayList;
import java.util.List;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

public interface CourseClassStuRepository extends JpaRepository<CourseClassStu, String> {
	
	public List<CourseClassStu> findAllByDeleteFlagAndCourseClassId(Integer deleteFlag,String courseClassId);
	public List<CourseClassStu> findAllByDeleteFlagAndCourseClassIdIn(Integer deleteFlag,List<String> courseClassIds);

	public List<CourseClassStu> findAllByDeleteFlagAndCourseClassIdInOrderByCourseClassIdAsc(Integer deleteFlag,List<String> courseClassIds);
	List<CourseClassStu> findByCourseIdAndDeleteFlag(String courseId,Integer deleteFlag);
	public long deleteByCourseClassId(String courseClassId);
	
	@Modifying
    @Query(value="update t_course_class_stu  set delete_flag=:deleteFlag where stu_id in :stuIds ",nativeQuery=true)
	public void updateByStuId(@Param("deleteFlag")Integer deleteFlag,@Param("stuIds")List<Long> stuIds);
	
	@Modifying
    @Query(value="update `t_course_class_stu` ccs set ccs.course_id =(select cc.course_id from `t_course_class` cc where ccs.course_class_id = cc.id) where ccs.delete_flag = 0 and ccs.course_id is null ",nativeQuery=true)
	public void initCourseId();
}
